<?php
namespace BoxEdu\Hooks;
class EduHooks extends \HooksController
{

    
    

    function member_load(&$param)
    {
					  // dump($this->view);exit();
							//	$content=$this->fetch("","123123");
							//	dump($content);exit();
        $user_id = $param['user_id'];
								$param['money']=intval($param['money']);
        $user_info_2 = (array)BoxModel("EduUser")->load($user_id);     //用户课程之类的信息
        $user_info_3 = (array)BoxModel("edu_students")->byField("user_id", $user_id);     //用户课程之类的信息
        $param = array_merge($param, $user_info_2, $user_info_3);
								$param['school_name']=$param['school']['name'];
    }

    function member_after_save_students(&$param)
    {
        $model = BoxModel("edu_students");
        $row = $model->create($param);
								$r=$model->where(array('user_id' => $param['user_id']))->find();
        if ($r) {
           $bool= $model->where(array('user_id' => $param['user_id']))->save($row);
        }else{
									 $row['add_time']=date("Y-m-d H:i:s");
									  $bool= $model->add($row);
								}
    }


    function add_apply_examination(&$param)
    {
        $data = array_diff(I(), $param);
        $param['data'] = unserialize($data);
    }

  //增加学币同时也增加经验值
  function log_after_add_money(&$row){
			  if(in_array($row['event'],array('00007','00011','00017','00019'))){
					  return ;
					}
			  $data=$row;
					$data['type']="xuebazi";
					$data['num']=intval($data['num'])*5;
					$template=BoxModel("system_log_template")->where(array('event'=>$data['event']))->find();
					$this->data=$data;
					if($template['content']){
									$data['remark']=$this->fetch("",stripslashes(htmlspecialchars_decode($template['content'])));
					}
					$data['remark']=str_replace("学币","经验值",$data['remark']);
					$data['event']="";
					//dump($data);exit();
     Logic("BoxSns","Log")->add($data);					
		}
		
}
